package com.fjwt.gz.proxy.ctrl.export;

import com.fjwt.gz.core.model.ApiRes;
import com.fjwt.gz.db.dto.FansDTO;
import com.fjwt.gz.db.vo.FansVO;
import com.fjwt.gz.db.vo.ScoreRecordTotalVO;

import com.fjwt.gz.proxy.ctrl.CommonCtrl;
import com.fjwt.gz.service.impl.ActivityService;
import com.fjwt.gz.service.impl.FansService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/exportExcel")
public class ExportExcelController extends CommonCtrl {

    @Autowired
    private ActivityService activityService;

    @Autowired
    private FansService fansService;

    /**
     * 导出某个活动的报表
     */
    @PreAuthorize("hasAnyAuthority('ENT_ACTIVITY_LIST_INFO_EXPT_STMT')")
    @PostMapping("/exportActivityAward")
    public ApiRes exportActivityAward() {
        Long activityId = getValLong("activityId");
        log.info("机构端导出活动报表，请求地址：/api/exportExcel/exportActivityAward，请求参数：activityId:{}", activityId);
        return activityService.exportActivity(activityId, getCurrentUser().getSysUser());
    }


    /**
     * 导出列表用户数据
     */

    @PostMapping("/listExportWechat")
    public ApiRes ListExportWechat(HttpServletResponse response) {
        FansDTO dto = getObject(FansDTO.class);
        log.info("pc端会员管理-列表查询，请求地址：/api/fans/list，请求参数：dto：{}", dto);
        String agentNo = getCurrentUser().getAgentNo();
        dto.setAgentNo(checkAgentAuth(agentNo, dto.getAgentNo()));
        FansDTO vo = new FansDTO();
        BeanUtils.copyProperties(dto, vo);
        List<FansVO> list = fansService.getList(dto);
        String s = fansService.ListExportWechat(list, response);
        return ApiRes.ok(s);
    }

    /**
     * 导出福分详情数据数据
     */
    @PostMapping("/recordExportWechat")
    public ApiRes RecordExportWechat(HttpServletResponse response) {
        FansDTO fansDTO = getObject(FansDTO.class);
        FansDTO vo = new FansDTO();
        BeanUtils.copyProperties(fansDTO, vo);
        log.info("pc端会员管理-列表查询，请求地址：/api/fans/list，请求参数：dto：{}", fansDTO);
        List<ScoreRecordTotalVO> list = fansService.getRecordOfBlessings(vo);
        String s = fansService.RecordExportWechat(list, response);
        return ApiRes.ok(s);
    }


    /**
     * acte017数据导出
     * @return
     */
    @PostMapping("/exportActivityInfo")
    public ApiRes exportActivityInfo(){
        String awardId = getValString("awardId");
        String awardType = getValString("awardType");
        String activityId = getValString("activityId");
        activityService.exportActivityInfo(awardId, awardType, activityId);
        return ApiRes.ok();
    }
}
